package com.news.sentiment.vo;

import com.news.sentiment.enums.ResultEnum;
import lombok.Data;

@Data
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    public Result(Integer code, String msg) {
        this.code=code;
        this.msg=msg;
    }

    public Result(T data) {
        this.code=ResultEnum.REQUEST_SUCCESS.getCode();
        this.msg=ResultEnum.REQUEST_SUCCESS.getMsg();
        this.data=data;
    }
    public Result(){
        this.code=ResultEnum.REQUEST_SUCCESS.getCode();
        this.msg=ResultEnum.REQUEST_SUCCESS.getMsg();
    }
    public static Result fail(ResultEnum resultEnum){
        return new Result(resultEnum.getCode(),resultEnum.getMsg());
    }

    public static <T> Result<T> success(T data){
        return new Result<T>(data);
    }

    public static Result success(){
        return new Result();
    }
}
